package com.company.service.impl;

import com.company.service.GetNovelTypesService;
import com.company.service.GetNovelsService;
import org.junit.Test;

import java.io.*;
import java.util.Scanner;

public class GetNovelsServiceImpl implements GetNovelsService {
    @Override
    public void execute() {

    }
    public void show(int choose){
        Scanner input = new Scanner(System.in);
        Reader read=null;
        System.out.println("------------------小说列表开始--------------------");
        System.out.println("序号\t\t名称\t\t\t作者\t\t简介");
        if (choose==1) {
            try {
                read = new FileReader("/Users/l/Desktop/Project/yanqing.txt");
                char[] chars = new char[1024];
                int n;
                while ((n=read.read(chars))!=-1){
                    System.out.println(new String(chars,0,n));
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            finally{
                try {
                    read.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }else if(choose==2){
            try {
                read = new FileReader("/Users/l/Desktop/Project/wuxia.txt");
                char[] chars = new char[1024];
                int n;
                while ((n=read.read(chars))!=-1){
                    System.out.println(new String(chars,0,n));
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            finally{
                try {
                    read.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        System.out.println("-------------------小说列表结束------------------");
        System.out.print("0.返回上一级菜单: ");
        System.out.print("\n-1.上传小说: ");
        System.out.println("\n输入小说序号阅读: ");
        switch (input.nextInt()){
            case 0:
                GetNovelTypesService getNovelTypesService = new GetNovelTypesServiceImpl();
                getNovelTypesService.execute();
                break;
            case -1:
                GetNovelDataServiceImpl getNovelDataService = new GetNovelDataServiceImpl();
                getNovelDataService.execute();
                break;
            case 1:
                System.out.println("-----");
                break;
            case 2:
                System.out.println("-----");
                break;
            default:
                System.out.println("输入错误,请重新输入");
        }
    }
}
